package srx.open.com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import srx.open.com.R;
import srx.open.com.bean.CoursePublish;
import srx.open.com.utils.DataBaseHelper;
import srx.open.com.widgets.CircleImageView;

/**
 * 首页推荐，附近课程的基类.
 */
public abstract class BaseCoursePublishAdpter  extends BaseAdapter{

    public final static int MAX_CONTENT_NUMBER = 44;
    public final static int MAX_TITLE_NUMBER = 20;

    public LayoutInflater mInflater;
    public List<CoursePublish> mPubList;
    public DataBaseHelper mDataBaseHelper;
    public Context mContext;

    public BaseCoursePublishAdpter(final Context context,
                               final List<CoursePublish> pubList,
                               final DataBaseHelper dataBaseHelper) {
        mInflater = LayoutInflater.from(context);
        mPubList = pubList;
        mDataBaseHelper = dataBaseHelper;
        mContext = context;
    }

    public void setPubList(List<CoursePublish> pubList) {
        mPubList = pubList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mPubList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = bindView(position, convertView, parent);
        return convertView;
    }

    public abstract View bindView(int position, View convertView,
                                  ViewGroup parent);

    public class MyViewHolder {
        public TextView home_recommend_title_tv;        // 标题栏.
        public TextView home_recommend_content_tv; // 内容.
        public TextView home_recommend_location_tv;  // 位置
        public TextView home_recommend_time_tv;       // 创建时间.
        public CircleImageView home_avatar_iv; // 头像.

        public MyViewHolder(View v) {
            home_recommend_title_tv = (TextView) v.findViewById(R.id.home_recommend_title_tv);
            home_recommend_content_tv = (TextView) v.findViewById(R.id.home_recommend_content_tv);
            home_recommend_location_tv = (TextView) v.findViewById(R.id.home_recommend_location_tv);
            home_recommend_time_tv = (TextView) v.findViewById(R.id.home_recommend_time_tv);
        }
    }

}
